#pragma once


/**
 * 程序是rsa 32bit的加解密功能
 * 支持以32bit为宽度操作数据，但计算机需支持64bit宽度的计算
 * 代码暂未支持大数计算，所以秘钥的长度也为32bit大小
 * 若加密失败，则尝试更换更大的p，q的值
 */

struct rsa32b_key
{
    int q;     // big prime number
    int p;     // big prime number
    int n;     // p * q
    // int fai_n; // φ(n) = (p-1)*(q-1)
    int e;     // 1 < e < φ(n), e is Prime with φ(n), normal will set 65537
    int d;     // d·e≡1 mod φ(n)
    // expand
    int padding;    
};

struct sign_info
{
    // char *version;
    char *serialNumber;
    char *hash;     // SHA1 ...    
    char *name;
    char *validity;
};

int rsa32b_key_init_from_certificate(struct rsa32b_key *rkey, char *buff);
int rsa32b_key_init_from_certificateF(struct rsa32b_key *rkey, char *filename);
int rsa32b_key_create(struct rsa32b_key *rkey, int p, int q, int e);
int rsa32b_key_generate_publicKey(struct rsa32b_key *rkey, struct sign_info *info, char *filename);
int rsa32b_key_generate_privateKey(struct rsa32b_key *rkey, struct sign_info *info, char *filename);
int rsa32b_public_encrypt(struct rsa32b_key *rkey, char *pla, char *out, int len);
int rsa32b_public_decrypt(struct rsa32b_key *rkey, char *cip, char *out, int len);
int rsa32b_private_encrypt(struct rsa32b_key *rkey, char *pla, char *out, int len);
int rsa32b_private_decrypt(struct rsa32b_key *rkey, char *cip, char *out, int len);

